package com.lntea.security.sha;

import java.security.MessageDigest;
import java.security.Security;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class LnteaSHA {
	private static String message = "lntea sha";
	public static void main(String[] args) {
		jdkSHA();
		
		ccSHA();
	}
	
	public static void jdkSHA(){
		Security.addProvider(new BouncyCastleProvider());
		try {
			MessageDigest md = MessageDigest.getInstance("sha");
			byte[] digestBytes = md.digest(message.getBytes());
			System.out.println("jdk sha:"+new String(Base64.encodeBase64(digestBytes)));
			
			md = MessageDigest.getInstance("sha-224");
			digestBytes = md.digest(message.getBytes());
			System.out.println("jdk sha 224:"+new String(Base64.encodeBase64(digestBytes)));
			
			md = MessageDigest.getInstance("sha-256");
			digestBytes = md.digest(message.getBytes());
			System.out.println("jdk sha 256:"+new String(Base64.encodeBase64(digestBytes)));
			
			md = MessageDigest.getInstance("sha-384");
			digestBytes = md.digest(message.getBytes());
			System.out.println("jdk sha 384:"+new String(Base64.encodeBase64(digestBytes)));
			
			md = MessageDigest.getInstance("sha-512");
			digestBytes = md.digest(message.getBytes());
			System.out.println("jdk sha 512:"+new String(Base64.encodeBase64(digestBytes)));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void ccSHA(){
		byte[] digestBytes = DigestUtils.sha1(message.getBytes());
		System.out.println("cc sha:"+new String(Base64.encodeBase64(digestBytes)));
		
		String digestStr = DigestUtils.sha512Hex(message.getBytes());
		System.out.println("cc sha512:"+digestStr);
	}
}
